<?php
include "includes/sesiones.php";
include "includes/comunes.php";


$where=" 1=1";
       if($_GET['fdesde']<>"")
      $where.=" and vencimiento >='".trim($_GET['fdesde'])."' ";
    if($_GET['fhasta']<>"")
      $where.=" and vencimiento <='".trim($_GET['fhasta'])."' ";
$sql="select * from cuotascredito where ".$where." order by creditoId asc";
//echo $sql;

$rescre=  cons_ins($sql);

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Listado de Vencimientos</title>
<style>
body{
font-family:Arial;
}
</style>
</head>

<body>
<table width="100%" border="0">
  <tr>
    <td height="53" colspan="2"><div align="center" class="Estilo1"><b>CREDITOS PARA TODOS </b></div></td>
    <td width="14%"><div align="center" class="Estilo2"><b>Fecha Emision: </b></div></td>
    <td width="18%"><div align="center" class="Estilo2"><b>&nbsp;<?php echo date("d/m/Y");?></b></div></td>
    <td width="11%"><div align="center" class="Estilo2"><b>Emitido por: </b></div></td>
    <td width="19%"><div align="center" class="Estilo2"><b>&nbsp;<?php echo $_SESSION['Usuario'];?></b></div></td>
  </tr>
  <tr>
    <td width="19%" style="border-top: 1px solid #666666"><div align="left" class="Estilo6"><b>Rango Fechas</b></div></td>
    <td colspan="5" style="border-top: 1px solid #666666"><div align="left"><b>Desde <?php echo format_fec($_GET['fdesde'],"/");?> - Hasta <?php echo format_fec($_GET['fhasta'],"/");?></b></div></td>
  </tr>
  <tr>
    <td colspan="6" style="border-top: 1px solid #666666"><table width="100%" border="0">
	
 </tr>   
           <?php
      $tot=0;
      $can=0;
      $totCap=0;
      $totInt=0;
	  $totPag=0;
	  $totVdo=0;
	  $totVdoNoPag=0;
	  $totNoPag=0;
      ?>
            <tr>
        <td width="10%" style="border: 1px solid #666666"><div align="center" class="Estilo6"><b>Credito</b> </div></td>
        <td width="10%" style="border: 1px solid #666666"><div align="center" class="Estilo6"><b>Cliente</b></div></td>
       <td width="10%" style="border: 1px solid #666666"><div align="center" class="Estilo6"><b>Cuota</b></div></td>
        <td width="10%" style="border: 1px solid #666666"><div align="center" class="Estilo6"><b>Vto</b></div></td>
        <td width="10%" style="border: 1px solid #666666"><div align="center" class="Estilo6"><b>Capital</b></div></td>
        <td width="10%" style="border: 1px solid #666666"><div align="center" class="Estilo6"><b>Intereses</b> </div></td>
        <td width="10%" style="border: 1px solid #666666"><div align="center" class="Estilo6"><b>Total</b> </div></td>
        <td width="30%" style="border: 1px solid #666666"><div align="center" class="Estilo6"><b>Estado</b></div></td>
            </tr>   
	
      
	      <?php
      while ( $regcre=mysql_fetch_array($rescre)):
	   if(existe_credito($regcre['creditoId'])>0):
      ?>
            <tr>
        <td width="10%" style="border: 1px solid #666666"><div align="center" class="Estilo6"><?php echo $regcre['creditoId']?></div></td>
        <td width="10%" style="border: 1px solid #666666"><div align="center" class="Estilo6"><?php echo obtener_cliente(obtener_cliente_credito($regcre['creditoId']))?></div></td>
       <td width="10%" style="border: 1px solid #666666"><div align="center" class="Estilo6"><?php echo $regcre['cuota']?></div></td>
        <td width="10%" style="border: 1px solid #666666"><div align="center" class="Estilo6"><?php echo format_fec($regcre['vencimiento'],"/")?></div></td>
        <td width="10%" style="border: 1px solid #666666"><div align="center" class="Estilo6">$ <?php echo $regcre['capital']?></div></td>
        <td width="10%" style="border: 1px solid #666666"><div align="center" class="Estilo6">$ <?php echo $regcre['intereses']?> </div></td>
        <td width="10%" style="border: 1px solid #666666"><div align="center" class="Estilo6">$ <?php echo $regcre['intereses']+$regcre['capital']?> </div></td>
        <td width="30%" style="border: 1px solid #666666"><div align="center" class="Estilo6" <?php if($regcre['estado']==2) echo "style=color:green;"; else echo "style=color:red;"?>>
		<?php echo obtener_estado($regcre['estado'])?>
		</div></td>
            </tr>
    
  <?php  
  $can++;
  $totCap+=$regcre['capital'];
  $totInt+=$regcre['intereses'];
  $tot+=$regcre['intereses']+$regcre['capital'];
   if($regcre['estado']==1){
    $totNoPag+=$regcre['intereses']+$regcre['capital'];
	 if($regcre['vencimiento'] < date("Y-m-d"))
		$totVdoNoPag+=$regcre['intereses']+$regcre['capital'];
	}
	else
	$totPag+=$regcre['intereses']+$regcre['capital'];
  endif  ;
 endwhile
      ?>
      

             <tr>
          <td colspan="8" style="border: 1px solid #666666"><div align="left" class="Estilo3"><b>Total: $<?php echo $tot?> - Can. de Ope: <?php echo $can;?></b></div>          <div align="left" class="Estilo3"></div>          <div align="left" class="Estilo3"></div>          <div align="left" class="Estilo3"></div>          <div align="left" class="Estilo3"></div>          <div align="left" class="Estilo3"></div></td>
        </tr>
	  <tr>
        <td colspan="4" style="border: 1px solid #666666"><div align="center" class="Estilo6">
          <div align="right"><b>Total Pagado</b></div>
        </div>          <div align="center" class="Estilo6"></div>          </td>
        <td colspan="4" style="border: 1px solid #666666">&nbsp; <b>$ <?php echo $totPag ?></b></td>
      </tr>
	  <tr>
        <td colspan="4" style="border: 1px solid #666666"><div align="center" class="Estilo6">
          <div align="right"><b>Total Adeudado</b></div>
        </div>          <div align="center" class="Estilo6"></div>          </td>
        <td colspan="4" style="border: 1px solid #666666">&nbsp; <b>$ <?php echo $totNoPag ?></b></td>
      </tr>
	   <tr>
        <td colspan="4" style="border: 1px solid #666666"><div align="center" class="Estilo6">
          <div align="right"><b>Total Vencido No Pagado</b></div>
        </div>          <div align="center" class="Estilo6"></div>          </td>
        <td colspan="4" style="border: 1px solid #666666">&nbsp; <b>$ <?php echo $totVdoNoPag ?></b></td>
      </tr>
	

</table>
</body>
</html>
